package com.example.demo.config;

import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.example.demo.pojo.Result;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RestControllerAdvice
public class MyExceptionHandler {
//全局异常类
	@ExceptionHandler(SignatureVerificationException.class)
	public Result testException(SignatureVerificationException signatureVerificationException) {
		return Result.success("签名异常");
	}

	@ExceptionHandler(TokenExpiredException.class)
	public Result testException(TokenExpiredException tokenExpiredException) {
		return Result.success("token过期");
	}

	@ExceptionHandler(AlgorithmMismatchException.class)
	public Result testException(AlgorithmMismatchException AlgorithmMismatchException) {
		return Result.success("加密算法不匹配");
	}

	@ExceptionHandler(Exception.class)//捕获所有异常
	public Result ex(Exception exception){
		exception.printStackTrace();
		return Result.error("对不起，操作失败，请联系管理员");
	}
}

